/**
 * 
 */
package com.infodms.dms.actions.sales.fleetmanage.fleetInfoManage;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.dao.sales.fleetmanage.fleetsupport.FleetSupportDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TmFleetFollowPO;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;

/**
 * @Title: 集团客户跟进维护Action
 * @Description:InfoFrame3.0.V01
 * @Copyright: Copyright (c) 2010
 * @Company: www.infoservice.com.cn
 * @Date: 2010-8-20
 * @author 
 * @mail:lishuai103@yahoo.cn
 * @version 1.0
 * @remark 
 */
public class FleetFollow {
	public Logger logger = Logger.getLogger(FleetFollow.class);   
	FleetSupportDao dao  = FleetSupportDao.getInstance();
	private ActionContext act = ActionContext.getContext();
	RequestWrapper request = act.getRequest();
	private final String initUrl = "/jsp/sales/fleetmanage/fleetSupport/fleetFollowProtect.jsp";
	private final String queryinitUrl = "/jsp/sales/fleetmanage/fleetSupport/queryfollow.jsp";
	private final String detailUrl = "/jsp/sales/fleetmanage/fleetSupport/fleetFollowCheck.jsp";
	private final String detailInfoUrl = "/jsp/sales/fleetmanage/fleetSupport/fleetFollowInfo.jsp";
	
	/*
	 * 集团客户跟进初始化
	 */
	public void searchFollowInit(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			act.setForword(initUrl);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"集团客户跟进信息维护");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/*
	 * 集团客户跟进查询
	 */
	public void fleetFollowforquery(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String fleetName = request.getParamValue("fleetName");	//客户名称
			String fleetType = request.getParamValue("fleetType");	//客户类型
			String startDate = request.getParamValue("startDate");	//起始时间
			String endDate = request.getParamValue("endDate");		//结束时间
			String dutyType = logonUser.getDutyType();
			String companyId = String.valueOf(logonUser.getCompanyId());
			String orgId = String.valueOf(logonUser.getOrgId());
			Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			PageResult<Map<String, Object>> ps = dao.fleetFollowCheckQuery(orgId, dutyType, fleetName, fleetType, startDate, endDate, companyId, curPage, Constant.PAGE_SIZE);
			act.setOutData("ps", ps);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"集团客户支持财务复核查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 集团客户跟进查询专用
	 */
	
	public void fleetFollowforqueryList(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String fleetName = request.getParamValue("fleetName");	//客户名称
			String fleetType = request.getParamValue("fleetType");	//客户类型
			String startDate = request.getParamValue("startDate");	//起始时间
			String endDate = request.getParamValue("endDate");		//结束时间
			String dutyType = logonUser.getDutyType();
			String companyId = String.valueOf(logonUser.getCompanyId());
			String orgId = String.valueOf(logonUser.getOrgId());
			Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			PageResult<Map<String, Object>> ps = dao.fleetFollowCheckQueryList(orgId, dutyType, fleetName, fleetType, startDate, endDate, companyId, curPage, Constant.PAGE_SIZE);
			act.setOutData("ps", ps);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"集团客户支持财务复核查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/*
	 * 集团客户跟进
	 */
	public void fleetFollowCheck(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String fleetId = request.getParamValue("fleetId");	//客户Id
			String intentId = request.getParamValue("intentId");	//意向Id
			String contractId=request.getParamValue("contractId");//合同ID
			Map<String, Object> map = dao.getFleetInfobyId(fleetId);
			Map<String, Object> map2 = dao.getFleetIntentInfobyId(fleetId);
			List<Map<String, Object>> list1 = dao.getFleetIntentDetailInfobyId(fleetId, intentId,contractId);
			//List<Map<String, Object>> list2 = dao.getFleetIntentCheckInfobyId(fleetId, intentId);
			List<Map<String, Object>> list3 = dao.getFleetFollowbyId(fleetId, intentId);
			//act.setOutData("checkList", list2);
			//act.setOutData("intentId", intentId);
			act.setOutData("intentList", list1);
			act.setOutData("list3", list3);
			act.setOutData("intentMap", map2);
			act.setOutData("fleetMap", map);
			act.setForword(detailUrl);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"集团客户跟进");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/*
	 * 跟进操作
	 */
	public void fleetFollowCheckdo(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String fleetId = request.getParamValue("fleetId");	//客户Id
			//String intentId = request.getParamValue("intentId");	//意向Id
			String followDate = request.getParamValue("followDate");//跟进时间
			String remark = request.getParamValue("remark");//跟进内容
			TmFleetFollowPO po = new TmFleetFollowPO();
			SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
			po.setFollowId(Long.parseLong(SequenceManager.getSequence("")));
			po.setFleetId(Long.parseLong(fleetId));
			//po.setIntentId(Long.parseLong(intentId));
			po.setFollowDate(f.parse(followDate));
			po.setFollowRemark(remark);
			po.setStatus(Constant.STATUS_ENABLE);
			po.setCreateBy(logonUser.getUserId());
			po.setCreateDate(new Date());
			dao.insert(po);
			act.setOutData("returnValue", 1);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"集团客户跟进");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void queryFollowInit(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			act.setForword(queryinitUrl);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"集团客户跟进信息维护");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void fleetFollowInfo(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String fleetId = request.getParamValue("fleetId");	//客户Id
			String intentId = request.getParamValue("intentId");	//意向Id
			Map<String, Object> map = dao.getFleetInfobyId(fleetId);
			Map<String, Object> map2 = dao.getFleetIntentInfobyId(fleetId);
			List<Map<String, Object>> list1 = dao.getFleetIntentDetailInfobyId(fleetId, intentId,"");
			List<Map<String, Object>> list2 = dao.getFleetIntentCheckInfobyId(fleetId, intentId);
			List<Map<String, Object>> list3 = dao.getFleetFollowbyId(fleetId, intentId);
			act.setOutData("intentList", list1);
			act.setOutData("checkList", list2);
			act.setOutData("list3", list3);
			act.setOutData("intentMap", map2);
			act.setOutData("intentId", intentId);
			act.setOutData("fleetMap", map);
			act.setForword(detailInfoUrl);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"集团客户跟进");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
}
